<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@include file="/common/common.jspf"%>

<script type="text/javascript"
	src="${ctx}/js/forming/changeshifts/inspect_edit.js"></script>
<script type="text/javascript">
	$(function() {
		var i = 0;
		$("#add").attr("disabled", true);
		$("#search").click("click",function() {
			deleteTblObj();
			var client = $("#client").val().split("/");
			K = obj.insertRow(obj.rows.length);
			O = K.insertCell(0);
			O.innerHTML = '<div class="input-group"><input  style="width:276px;" type="text" class="form-control" name="moldingInspectionFormMap.Check_Inspection" value="'+client[1]+'"></div>';
			O = K.insertCell(1);
			O.innerHTML = '<input type="button" class="btn btn-danger" onclick ="deleteItem(this)"  value ="删除"><input type="hidden" class="btn btn-danger" name="moldingInspectionFormMap.id" value ="'+client[0]+'">';
			$("#add").attr("disabled", false);
				jQuery.ajax({
					    "type" : "post",//请求方式
						"url" : "${pageContext.request.contextPath}/handover/inspect_searchEntity.shtml", //请求路径
						"data" : {"id" : client[0]}, //带参数数据
						"dataType" : "json",//数据类型
						"success" : function(user) { //成功后 （预计返回的是user）
							if (user != null && user != '') {
								for (var j = 0; j < user.length; j++) {
									i++;
									R = tbl.insertRow(tbl.rows.length);
									C = R.insertCell(0);
									C.innerHTML = '<input  style="width:276px;" type="text" class="form-control" name="Check_Content" value="'+user[j].Check_Content+'">';
									C = R.insertCell(1);
									C.innerHTML = '<input type="button" class="btn btn-danger" onclick ="deleteRow(this)" value ="删除">';
								}
							} else {
								alert('暂时无数据！');
								}
							}
					});
			});
			
			$("#addItem").click("click",function() {
				layer.confirm('是否新增项目？',function(index) {
					addAccount();
					});
			});
	});
	///删除项目
	function deleteItem(obj) {
		var id = $(obj).next().val();
		layer.confirm('是否删除？',function(index) {
			jQuery.ajax({
						"type" : "post",//请求方式
						"url" : "${pageContext.request.contextPath}/handover/inspect_itemDeleteEntity.shtml", //请求路径
						"data" : {"id" : id}, //带参数数据
						"dataType" : "json",//数据类型
						"success" : function(s) { //成功后 
							if (s == "success") {
								layer.msg('删除成功');
								history.go(0);

							} else {
								layer.msg('删除失败');
								history.go(0);
							}

						},"error" : function() { //有异常
								alert('系统发生异常，请联系管理员！');
							}
						});
				});
	}

	function deleteRow(obj) {
		var i = obj.parentNode.parentNode.rowIndex;
		if (i > 0) {
			tbl.deleteRow(i - 1);
		}
	}

	function deleteTblObj() {
		var tbl = document.getElementById("tbl");
		var obj = document.getElementById("obj");
		while (tbl.hasChildNodes()) {
			tbl.removeChild(tbl.firstChild);
		}
		while (obj.hasChildNodes()) {
			obj.removeChild(obj.firstChild);
		}

	}
	function insert_row(obj) {
		R = tbl.insertRow(tbl.rows.length);
		C = R.insertCell(0);
		C.innerHTML = '<input  style="width:276px;" type="text" class="form-control" name="Check_Content" value="">';
		C = R.insertCell(1);
		C.innerHTML = '<input type="button" class="btn btn-danger" onclick ="deleteRow(this)" value ="删除">';
	}
	function addAccount() {
		pageii = layer.open({
			title : "新增点检项目内容",
			type : 2,
			area : [ "800px", "100%" ],
			content : rootPath + '/handover/inspect_add.shtml'
		});
	}
</script>
<style type="text/css">
.col-sm-3 {
	width: 15%;
	float: left;
}

.col-sm-9 {
	width: 85%;
	float: left;
}

label[class^="btn btn-default"] {
	margin-top: -4px;
}
</style>
</head>
<body>
	<div class="l_err" style="width: 100%; margin-top: 2px;"></div>

	<label class="col-sm-3 control-label">点检项目：</label>

	<select style="width: 30%; display: inline;" class="form-control"
		id="client" name="moldingInspectionFormMap.Check_Inspection">
		<c:forEach var="key" items="${inspection}">
			<option value="${key.id}/${key.Check_Inspection}">${key.Check_Inspection}</option>
		</c:forEach>
	</select>
	<button type="button" id="search" class="btn btn-success btn-s-xs" style="display: inline;">查询</button>
	<button type="button" id="addItem" class="btn btn-success btn-s-xs" style="display: inline;">新增</button>
	<form id="form" name="form" class="form-horizontal" method="post"
		action="${ctx}/handover/inspect_editItemEntity.shtml">

		<section class="panel panel-default">
		<div class="panel-body">
			<div class="panel panel-default">
				<div class="panel-body">
					<table class="table table-bordered">
						<thead>
							<tr>
								<th style="width: 276px;">点检项目</th>
								<th style="width: 20px;"></th>
							</tr>
						</thead>
						<tbody id="obj">
						</tbody>
					</table>
				</div>
			</div>
			<div class="panel panel-default">
				<div class="panel-body">
					<table class="table table-bordered">
						<thead>
							<tr>
								<th style="width: 276px;">点检内容</th>
								<th style="width: 20px;"><input type="button"
									class="btn btn-danger" id="add" onclick="insert_row(this)"
									value="增加"></th>
							</tr>
						</thead>
						<tbody id="tbl">
						</tbody>
					</table>
				</div>
			</div>

		</div>
		<footer class="panel-footer text-right bg-light lter">
		<button type="submit" class="btn btn-success btn-s-xs">提交</button>
		</footer> </section>
	</form>
</body>
</html>